var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { wasm_init, wasm_hasInit, wasm_getImports, wasm_getExports } from "../libWasm.js";
var _export;
export function InitWasm() {
    return __awaiter(this, void 0, void 0, function* () {
        //先替换掉我们想导出给wasm的函数
        var imports = wasm_getImports();
        imports["hello"] = () => {
            console.log("hello   call from wasm");
        };
        //然后启动wasm
        wasm_init();
        //等待wasm准备好
        while (!wasm_hasInit()) {
            yield new Promise(resolve => requestAnimationFrame(resolve));
        }
        //执行两个测试
        _export = wasm_getExports();
        var v = _export.Add(3, 4);
        console.log("test1 add=" + v);
        _export.Good();
        console.log("test2 good");
    });
}
export function GetWasmFunc(name) {
    return _export[name];
}
export function GetWasmExports() {
    return _export;
}
